package com.ruoyi.iot.listener;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.iot.service.IDeviceService;
import com.ruoyi.iotcommon.constant.RocketTopicConstant;
import com.ruoyi.iotcommon.domain.OnlineStatusMessage;

/**
 * 在线状态监听器
 */
@Service
@RocketMQMessageListener( topic = RocketTopicConstant.ONLINE_STATUS, consumerGroup = "iot-core-device-onlineStatus")
public class OnlineStatusListener implements RocketMQListener<OnlineStatusMessage>{

    @Autowired
    private IDeviceService deviceService;

    @Override
    public void onMessage(OnlineStatusMessage message) {
        // 更新数据库设备在线状态
        deviceService.updateOnlineStatus(message.getProductKey(), message.getDeviceKey(), message.getStatus());
    }
    
}
